package com.kzj.laimeimei.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ab.util.AbViewUtil;
import com.kzj.laimeimei.R;
import com.kzj.laimeimei.recyclerCard.basic.MaterialListView;
import com.kzj.laimeimei.recyclerCard.basic.OnButtonPressListener;
import com.kzj.laimeimei.recyclerCard.card.Card;
import com.kzj.laimeimei.recyclerCard.card.ExtendedCard;

/**
 * Created by Administrator on 2015/11/11.
 */
public class ContainerDialog extends Dialog {
    private static MaterialListView materialListView;
    private CardOnClick cardOnClick;
    private int listViewHeight;
    private static ViewGroup.LayoutParams layoutParams;

    public ContainerDialog(Context context) {
        super(context);
    }

    public ContainerDialog(Context context, int theme) {
        super(context, theme);
    }

    public static ContainerDialog createDialog(Context context) {
        ContainerDialog dialog = new ContainerDialog(context, R.style.style_share_dialog);
        dialog.getWindow().setWindowAnimations(R.style.dialogWindowAnim);
        View mView = LayoutInflater.from(context).inflate(R.layout.dialog_container, null);
        AbViewUtil.scaleContentView((ViewGroup) mView);
        materialListView = (MaterialListView) mView.findViewById(R.id.material_listview);
        layoutParams = materialListView.getLayoutParams();
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        dialog.setContentView(mView);
        return dialog;
    }

    public int getListViewHeight() {
        return listViewHeight;
    }

    public void setListViewHeight(int listViewHeight) {
        this.listViewHeight = listViewHeight;
        layoutParams.height = listViewHeight;
        materialListView.setLayoutParams(layoutParams);
    }

    public CardOnClick getCardOnClick() {
        return cardOnClick;
    }

    public void setCardOnClick(CardOnClick cardOnClick) {
        this.cardOnClick = cardOnClick;
    }

    public void addCard(ExtendedCard card) {
        card.setOnNormalButtonPressedListener(new OnButtonPressListener() {
            @Override
            public void onButtonPressedListener(View view, Card card) {
                if (cardOnClick != null)
                    cardOnClick.CardOnClickListener(view, card);
            }
        });
        materialListView.add(card);
    }

    public interface CardOnClick {
        public void CardOnClickListener(View view, Card card);
    }
}

